<!DOCTYPE html>
<html>
<head>
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?d890b1f16fb364253e79c5bb20225c3a";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>


    

    

    
<!-- Baidu Tongji -->
<script>var _hmt = _hmt || []</script>
<script async src="//hm.baidu.com/hm.js?busuanzi_value_site_uv"></script>
<!-- End Baidu Tongji -->




    <meta charset="utf-8">
    <meta name="baidu-site-verification" content="FYMCShbUK8" />
    <meta name="baidu-site-verification" content="ZYRF7OxQRW" />
    <meta name="baidu-site-verification" content="cHSqtjI0PN" />
    <meta name="baidu-site-verification" content="cHSqtjI0PN" />
    <meta name="baidu-site-verification" content="cHSqtjI0PN" />
    
    
    <link rel="canonical" href="https://hhardyy.com/2020/02/04/前端大文件分片/">
    
    
    <title>简单了解前端大文件分片 | 小方块 - hhardyy.com | 复杂的坑+归其原理+了解实现规则===解决？解决成功：加油解决成功;</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#958e93">
    
    
    <meta name="keywords" content="分片,静态资源,upload,文件服务,HDFS">
    <meta name="description" content="假设要把项目做成微服务架构，然后单独做个静态资源服务器。">
<meta name="keywords" content="分片,静态资源,upload,文件服务,HDFS">
<meta property="og:type" content="article">
<meta property="og:title" content="简单了解前端大文件分片">
<meta property="og:url" content="http://yoursite.com/2020/02/04/前端大文件分片/index.html">
<meta property="og:site_name" content="小方块 - hhardyy.com">
<meta property="og:description" content="假设要把项目做成微服务架构，然后单独做个静态资源服务器。">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://yoursite.com/images/upload/1.png">
<meta property="og:image" content="http://yoursite.com/images/upload/2.png">
<meta property="og:image" content="http://yoursite.com/images/upload/3.png">
<meta property="og:updated_time" content="2020-02-04T10:16:16.839Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="简单了解前端大文件分片">
<meta name="twitter:description" content="假设要把项目做成微服务架构，然后单独做个静态资源服务器。">
<meta name="twitter:image" content="http://yoursite.com/images/upload/1.png">
    
        <link rel="alternate" type="application/atom+xml" title="小方块 - hhardyy.com" href="/atom.xml">
    
    <link rel="shortcut icon" href="/hardyfavicon.ico">
    <link rel="stylesheet" href="//unpkg.com/hexo-theme-material-indigo@latest/css/style.css">
    <script>window.lazyScripts=[]</script>

    <!-- custom head -->
    

</head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide" >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/img/paulGraham.jpg)">
      <div class="brand" style="background-color:#4154b2">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="/img/avatar.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">BingZhenhuang</h5>
          <a href="mailto:huangbingzhen@hhardyy.com" title="huangbingzhen@hhardyy.com" class="mail">huangbingzhen@hhardyy.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/"  >
                <i class="icon icon-lg icon-home"></i>
                主页
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives"  >
                <i class="icon icon-lg icon-archives"></i>
                所有文章
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags"  >
                <i class="icon icon-lg icon-tags"></i>
                标签
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://github.com/HHardyy" target="_blank" >
                <i class="icon icon-lg icon-github"></i>
                Github
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://gitee.com/hhardyy" target="_blank" >
                <i class="icon icon-lg icon-cloud"></i>
                Gitee
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://juejin.im/user/59a26f926fb9a02487553b04"  >
                <i class="icon icon-lg icon-pencil"></i>
                掘金-圳
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://segmentfault.com/u/hhardyy"  >
                <i class="icon icon-lg icon-comments"></i>
                Segmentfault
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://codepen.io/HHardyy/" target="_blank" >
                <i class="icon icon-lg icon-codepen"></i>
                Codepen
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://www.freecodecamp.cn/hhardyy" target="_blank" >
                <i class="icon icon-lg icon-leaf"></i>
                Freecodecamp
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/友情链接"  >
                <i class="icon icon-lg icon-link"></i>
                友链
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">简单了解前端大文件分片</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">简单了解前端大文件分片</h1>
        <h5 class="subtitle">
            
                <time datetime="2020-02-04T04:03:07.000Z" itemprop="datePublished" class="page-time">
  2020-02-04
</time>


            
        </h5>
    </div>

    


</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#静态资源"><span class="post-toc-number">1.</span> <span class="post-toc-text">静态资源</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#文件服务hdfs"><span class="post-toc-number">1.1.</span> <span class="post-toc-text">文件服务hdfs</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#适用、不适用的场景"><span class="post-toc-number">1.1.1.</span> <span class="post-toc-text">适用、不适用的场景</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#HDFS局限"><span class="post-toc-number">1.1.2.</span> <span class="post-toc-text">HDFS局限</span></a></li></ol></li></ol></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#为什么要将文件分片"><span class="post-toc-number">2.</span> <span class="post-toc-text">为什么要将文件分片</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#分片上传原理"><span class="post-toc-number">3.</span> <span class="post-toc-text">分片上传原理</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#实现流程"><span class="post-toc-number">4.</span> <span class="post-toc-text">实现流程</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#具体实现"><span class="post-toc-number">5.</span> <span class="post-toc-text">具体实现</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#使用vue-simple-uploader"><span class="post-toc-number">6.</span> <span class="post-toc-text">使用vue-simple-uploader</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#原生的方式"><span class="post-toc-number">7.</span> <span class="post-toc-text">原生的方式</span></a></li></ol>
        </nav>
    </aside>
    
<article id="post-前端大文件分片"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">简单了解前端大文件分片</h1>
        <div class="post-meta">
            <time class="post-time" title="2020-02-04 12:03:07" datetime="2020-02-04T04:03:07.000Z"  itemprop="datePublished">2020-02-04</time>

            


            

        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <p>假设要把项目做成微服务架构，然后单独做个静态资源服务器。</p>
<p><iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width="330" height="86" src="//music.163.com/outchain/player?type=2&id=1384379256&auto=0&height=66"></iframe><br><a id="more"></a></p>
<p>假如项目要做成微服务架构，像我最近做的一个国际项目，里头的日志，静态资源等需要抽离成独立的服务。。。巴拉巴拉省略一万字。</p>
<h3 id="静态资源"><a href="#静态资源" class="headerlink" title="静态资源"></a>静态资源</h3><p>假如把静态资源单独做成一个微服务， 可以选择搭建一个HDFS 。。。具体步骤（省略很多字）</p>
<h4 id="文件服务hdfs"><a href="#文件服务hdfs" class="headerlink" title="文件服务hdfs"></a>文件服务hdfs</h4><p>HDFS（Hadoop Distributed File System），作为Google File System（GFS）的实现，是Hadoop项目的核心子项目，是分布式计算中数据存储管理的基础，是基于流数据模式访问和处理超大文件的需求而开发的，可以运行于廉价的商用服务器上。它所具有的高容错、高可靠性、高可扩展性、高获得性、高吞吐率等特征为海量数据提供了不怕故障的存储，为超大数据集（Large Data Set）的应用处理带来了很多便利。</p>
<h5 id="适用、不适用的场景"><a href="#适用、不适用的场景" class="headerlink" title="适用、不适用的场景"></a>适用、不适用的场景</h5><figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">高容错性、可构建在廉价机器上</div><div class="line">适合批处理</div><div class="line">适合大数据处理</div><div class="line">流式文件访问</div></pre></td></tr></table></figure>
<h5 id="HDFS局限"><a href="#HDFS局限" class="headerlink" title="HDFS局限"></a>HDFS局限</h5><figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">不支持低延迟访问</div><div class="line">不适合小文件存储</div><div class="line">不支持并发写入</div><div class="line">不支持修改</div></pre></td></tr></table></figure>
<h3 id="为什么要将文件分片"><a href="#为什么要将文件分片" class="headerlink" title="为什么要将文件分片"></a>为什么要将文件分片</h3><p>1、为了充分利用网络带宽，加快上传速度<br>2、避免断网，页面关闭等引起的文件上传失败导致文件丢失，需要重新上传</p>
<h3 id="分片上传原理"><a href="#分片上传原理" class="headerlink" title="分片上传原理"></a>分片上传原理</h3><p>将一个文件切割为一系列特定大小的小数据片，然后将这些小数据片分别上传到服务端，全部上传完后再由服务端将这些小数据片合并成为一个完整的资源。在上传的过程中即使遭受一些不确定因素影响导致上传中断，在恢复之后将继续该文件上次上传的进度继续上传，也就是断点续传。</p>
<p>举个栗子：<br>直接上传<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">传一个100M的文件，开始上传...0%..2%...99%...(断网) =&gt; 上传失败</div><div class="line">然后再传一次，开始上传...0%..2%...99%...(某些原因造成页面关闭) =&gt; 上传失败</div><div class="line">重新上传一次，开始上传...0%...</div></pre></td></tr></table></figure></p>
<p>分片<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">100M的文件，每个数据片大小5M，分20片上传</div><div class="line">开始上传...第一片...第二片...（断网）...第三片...(页面关闭)...第四片...（传完20片重组成文件）上传成功</div></pre></td></tr></table></figure></p>
<p>后端：实现分片上传的前提是需要服务器记录某文件的上传进度，根据该文件的唯一标识判读是否是同一个文件，可以利用文件内容根据（修改时间+文件名称+最后修改时间）求MD5码，如果上传的文件过大，求MD5码也是个稍微漫长的过程，所以对于太大的文件，只能针对其中某一段数据进行MD5，加上其他的鉴权得到唯一的key。</p>
<p>前端：将文件按照按照一定大小进行分片，一般每片大小在5M左右，可以同时发起多个请求，但一次同时请求的连接数不宜过多，否则服务器负载过重。可以利用H5强大的File Api，通过File对象的slice方法切出文件的一部分，切出的数据片是Blob。</p>
<h3 id="实现流程"><a href="#实现流程" class="headerlink" title="实现流程"></a>实现流程</h3><p>1、选择文件<br>2、根据（修改时间+文件名称+最后修改时间）计算MD5，以此来实现断点续传及秒传的功能，所以要等MD5计算完毕之后，再开始文件上传的操作。</p>
<blockquote>
<p>可以在这里做文件效验进度</p>
</blockquote>
<p>3、通过文件的MD5查询文件是否已经存在<br>4、检查并上传MD5</p>
<blockquote>
<p>可以在这里做文件上传进度</p>
</blockquote>
<p>5、上传完所有分片之后通知服务器进行合并 </p>
<h3 id="具体实现"><a href="#具体实现" class="headerlink" title="具体实现"></a>具体实现</h3><p>实现分片上传的方式有很多种:<br>百度的分片上传组件：<a href="http://fex.baidu.com/webuploader/" target="_blank" rel="external">WebUploader</a><br>vue-simple-uploader: vue-simple-uploader是基于 simple-uploader.js 封装的vue上传插件。使用之前瞄一眼<a href="https://github.com/simple-uploader/vue-uploader/blob/master/README_zh-CN.md" target="_blank" rel="external">vue-simple-uploader官方文档</a>， <a href="https://github.com/simple-uploader/Uploader/blob/develop/README_zh-CN.md" target="_blank" rel="external">simple-uploader.js官方文档</a>…以及其他的花里胡哨</p>
<h3 id="使用vue-simple-uploader"><a href="#使用vue-simple-uploader" class="headerlink" title="使用vue-simple-uploader"></a>使用vue-simple-uploader</h3><p>vue-simple-uploader的使用方法很简单,基本上就是配置参数<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm i vue-simple-uploader</div></pre></td></tr></table></figure></p>
<p>main.js或者其他导入的地方<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> vueSimpleUploader <span class="keyword">from</span> <span class="string">'vue-simple-uploader'</span>;</div><div class="line">Vue.use(vueSimpleUploader);</div><div class="line"><span class="string">`</span></div></pre></td></tr></table></figure></p>
<p>专门写个.vue文件来装它，叫upload-vue-simple-uploader.vue<br>template部分<br><figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">template</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">uploader</span></span></div><div class="line"><span class="tag">    <span class="attr">:options</span>=<span class="string">"options"</span></span></div><div class="line"><span class="tag">    <span class="attr">:file-status-text</span>=<span class="string">"statusText"</span></span></div><div class="line"><span class="tag">    @<span class="attr">file-complete</span>=<span class="string">"fileComplete"</span></span></div><div class="line"><span class="tag">    @<span class="attr">complete</span>=<span class="string">"complete"</span></span></div><div class="line"><span class="tag">    <span class="attr">class</span>=<span class="string">"uploader-example"</span></span></div><div class="line"><span class="tag">  &gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">uploader-unsupport</span>&gt;</span><span class="tag">&lt;/<span class="name">uploader-unsupport</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">uploader-drop</span>&gt;</span></div><div class="line">      <span class="tag">&lt;<span class="name">p</span>&gt;</span>请将文件拖拽到这里，或者<span class="tag">&lt;/<span class="name">p</span>&gt;</span></div><div class="line">      <span class="tag">&lt;<span class="name">uploader-btn</span>&gt;</span>请选择文件<span class="tag">&lt;/<span class="name">uploader-btn</span>&gt;</span></div><div class="line">      <span class="tag">&lt;<span class="name">uploader-btn</span> <span class="attr">:attrs</span>=<span class="string">"attrs"</span>&gt;</span>请选择图片<span class="tag">&lt;/<span class="name">uploader-btn</span>&gt;</span></div><div class="line">      <span class="tag">&lt;<span class="name">uploader-btn</span> <span class="attr">:directory</span>=<span class="string">"true"</span>&gt;</span>请选择目录<span class="tag">&lt;/<span class="name">uploader-btn</span>&gt;</span></div><div class="line">    <span class="tag">&lt;/<span class="name">uploader-drop</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">uploader-list</span>&gt;</span><span class="tag">&lt;/<span class="name">uploader-list</span>&gt;</span></div><div class="line">  <span class="tag">&lt;/<span class="name">uploader</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">template</span>&gt;</span></div></pre></td></tr></table></figure></p>
<p>js部分，options，attrs,statusText等都是它的配置项，可以翻看它的文档进行配置<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</div><div class="line">  data () &#123;</div><div class="line">    <span class="keyword">return</span> &#123;</div><div class="line">      options: &#123;</div><div class="line">        target: <span class="string">'http://127.0.0.1:3000/upload'</span>,   <span class="comment">//上传地址</span></div><div class="line">        chunkSize: <span class="number">5</span> * <span class="number">1024</span> * <span class="number">1024</span>,               <span class="comment">//分片大小</span></div><div class="line">        testChunks: <span class="literal">false</span>, <span class="comment">// 是否开启服务器分片校验(秒传)</span></div><div class="line">        maxChunkRetries: <span class="number">3</span>,  <span class="comment">//最大自动失败重试上传次数</span></div><div class="line">        checkChunkUploadedByResponse: <span class="function"><span class="keyword">function</span> (<span class="params">chunk, message</span>) </span>&#123;<span class="comment">// 服务器分片校验，断点续传基础</span></div><div class="line">            <span class="keyword">let</span> objMessage = <span class="built_in">JSON</span>.parse(message);</div><div class="line">            <span class="keyword">if</span> (objMessage.skipUpload) &#123;</div><div class="line">                <span class="keyword">return</span> <span class="literal">true</span>;</div><div class="line">            &#125;</div><div class="line">            <span class="keyword">return</span> (objMessage.uploaded || []).indexOf(chunk.offset + <span class="number">1</span>) &gt;= <span class="number">0</span></div><div class="line">        &#125;,</div><div class="line">        headers: &#123;</div><div class="line">            Authorization: <span class="string">"Bearer "</span> + <span class="string">"your accessToken"</span></div><div class="line">        &#125;,</div><div class="line">      &#125;,</div><div class="line">      attrs: &#123;</div><div class="line">        <span class="comment">//接受的文件类型，形如['.png', '.jpg', '.jpeg', '.gif', '.bmp'...]</span></div><div class="line">        accept: <span class="string">'image/*'</span>  </div><div class="line">      &#125;,</div><div class="line">      statusText: &#123;                       <span class="comment">//对应的状态说明</span></div><div class="line">        success: <span class="string">'上传成功'</span>,</div><div class="line">        error: <span class="string">'上传出错了'</span>,</div><div class="line">        uploading: <span class="string">'正在上传'</span>,</div><div class="line">        paused: <span class="string">'暂停中'</span>,</div><div class="line">        waiting: <span class="string">'等待中'</span></div><div class="line">      &#125;</div><div class="line">    &#125;</div><div class="line">  &#125;,</div><div class="line">  methods: &#123;</div><div class="line">    complete () &#123;</div><div class="line">      <span class="built_in">console</span>.log(<span class="string">'上传完成 complete'</span>, <span class="built_in">arguments</span>)</div><div class="line">    &#125;,</div><div class="line">    fileComplete () &#123;</div><div class="line">      <span class="built_in">console</span>.log(<span class="string">'文件上传完成 complete'</span>, <span class="built_in">arguments</span>)</div><div class="line">    &#125;</div><div class="line">  &#125;</div><div class="line">&#125;</div><div class="line"><span class="string">`</span></div></pre></td></tr></table></figure></p>
<p>style<br><figure class="highlight stylus"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line"><span class="selector-class">.uploader-example</span> &#123;</div><div class="line">  <span class="attribute">width</span>: <span class="number">880px</span>;</div><div class="line">  <span class="attribute">padding</span>: <span class="number">15px</span>;</div><div class="line">  <span class="attribute">margin</span>: <span class="number">40px</span> auto <span class="number">0</span>;</div><div class="line">  <span class="attribute">font-size</span>: <span class="number">12px</span>;</div><div class="line">  <span class="attribute">box-shadow</span>: <span class="number">0</span> <span class="number">0</span> <span class="number">10px</span> rgba(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0.4</span>);</div><div class="line">&#125;</div><div class="line"><span class="selector-class">.uploader-example</span> <span class="selector-class">.uploader-btn</span> &#123;</div><div class="line">  <span class="attribute">margin-right</span>: <span class="number">4px</span>;</div><div class="line">&#125;</div><div class="line"><span class="selector-class">.uploader-example</span> <span class="selector-class">.uploader-list</span> &#123;</div><div class="line">  <span class="attribute">max-height</span>: <span class="number">440px</span>;</div><div class="line">  <span class="attribute">overflow</span>: auto;</div><div class="line">  <span class="attribute">overflow-x</span>: hidden;</div><div class="line">  <span class="attribute">overflow-y</span>: auto;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>使用的时候直接import然后在components里头注册然后直接在页面上用，当然这只是方便快捷简单粗暴的demo<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> UploadVueSimpleUploader <span class="keyword">from</span> <span class="string">'@/components/upload-vue-simple-uploader'</span></div></pre></td></tr></table></figure></p>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="/images/upload/1.png" alt="使用效果" title="">
                </div>
                <div class="image-caption">使用效果</div>
            </figure>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="/images/upload/2.png" alt="上传一个mp3文件" title="">
                </div>
                <div class="image-caption">上传一个mp3文件</div>
            </figure>
<p>上传一个我比较喜欢的千与千寻《神隐》的10M大小的mp3文件，发现它上传成功了，然后发了两次请求，因为设置的分片大小是5M所以会发两次请求<br>然后此时后端接收到的数据是这个样子的，然后后端再把它重组就成了文件<br><figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="/images/upload/3.png" alt="后端接收到" title="">
                </div>
                <div class="image-caption">后端接收到</div>
            </figure></p>
<h3 id="原生的方式"><a href="#原生的方式" class="headerlink" title="原生的方式"></a>原生的方式</h3><p>原生的方式比上面那个方式稍微复杂一些,但是比较可控,首先是有DOM,当然都是比较随意的布局，好看可以用ElementUI或者自己写写样式。<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm install spark-md5</div></pre></td></tr></table></figure></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">template</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">div</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">input</span></span></div><div class="line"><span class="tag">          <span class="attr">type</span>=<span class="string">"file"</span></span></div><div class="line"><span class="tag">          <span class="attr">ref</span>=<span class="string">"file"</span></span></div><div class="line"><span class="tag">          @<span class="attr">change</span>=<span class="string">"fileChange"</span></span></div><div class="line"><span class="tag">        &gt;</span></div><div class="line">      <span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line"></div><div class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"process-wrap"</span>&gt;</span></div><div class="line">      <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"progress"</span>&gt;</span><span class="tag">&lt;<span class="name">span</span> <span class="attr">:style</span>=<span class="string">"style"</span>&gt;</span><span class="tag">&lt;/<span class="name">span</span>&gt;</span>校验进度：&#123;&#123;checkProcessStyle&#125;&#125;<span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line"></div><div class="line">    <span class="tag">&lt;<span class="name">br</span>&gt;</span></div><div class="line"></div><div class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"process-wrap"</span>&gt;</span></div><div class="line">      <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"progress"</span>&gt;</span><span class="tag">&lt;<span class="name">span</span> <span class="attr">:style</span>=<span class="string">"style1"</span>&gt;</span><span class="tag">&lt;/<span class="name">span</span>&gt;</span>上传进度：&#123;&#123;uploadProcessStyle&#125;&#125;<span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">template</span>&gt;</span></div></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div><div class="line">119</div><div class="line">120</div><div class="line">121</div><div class="line">122</div><div class="line">123</div><div class="line">124</div><div class="line">125</div><div class="line">126</div><div class="line">127</div><div class="line">128</div><div class="line">129</div><div class="line">130</div><div class="line">131</div><div class="line">132</div><div class="line">133</div><div class="line">134</div><div class="line">135</div><div class="line">136</div><div class="line">137</div><div class="line">138</div><div class="line">139</div><div class="line">140</div><div class="line">141</div><div class="line">142</div><div class="line">143</div><div class="line">144</div><div class="line">145</div><div class="line">146</div><div class="line">147</div><div class="line">148</div><div class="line">149</div><div class="line">150</div><div class="line">151</div><div class="line">152</div><div class="line">153</div><div class="line">154</div><div class="line">155</div><div class="line">156</div><div class="line">157</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">let</span> SparkMD5 = <span class="built_in">require</span>(<span class="string">'spark-md5'</span>)</div><div class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</div><div class="line">  data () &#123;</div><div class="line">    <span class="keyword">return</span> &#123;</div><div class="line">      checkProcessStyle: <span class="number">0</span>,</div><div class="line">      uploadProcessStyle: <span class="number">0</span>,</div><div class="line">      baseUrl: <span class="string">'http://localhost:3000'</span>,</div><div class="line">      chunkSize: <span class="number">5</span> * <span class="number">1024</span> * <span class="number">1024</span>,</div><div class="line">      fileSize: <span class="number">0</span>,</div><div class="line">      file: <span class="literal">null</span>,</div><div class="line">      hasUploaded: <span class="number">0</span>,</div><div class="line">      chunks: <span class="number">0</span></div><div class="line">    &#125;</div><div class="line">  &#125;,</div><div class="line">  computed: &#123;</div><div class="line">    style () &#123;</div><div class="line">      <span class="keyword">return</span> &#123;</div><div class="line">        width: <span class="keyword">this</span>.checkProcessStyle + <span class="string">'%'</span></div><div class="line">      &#125;</div><div class="line">    &#125;,</div><div class="line">    style1 () &#123;</div><div class="line">      <span class="keyword">return</span> &#123;</div><div class="line">        width: <span class="keyword">this</span>.uploadProcessStyle + <span class="string">'%'</span></div><div class="line">      &#125;</div><div class="line">    &#125;</div><div class="line">  &#125;,</div><div class="line">  methods: &#123;</div><div class="line">    <span class="comment">/* 选择文件 */</span></div><div class="line">    fileChange () &#123;</div><div class="line">      <span class="keyword">this</span>.file = <span class="keyword">this</span>.$refs.file.files[<span class="number">0</span>]</div><div class="line">      <span class="keyword">this</span>.fileSize = <span class="keyword">this</span>.file.size</div><div class="line">      <span class="keyword">this</span>.resChange(<span class="keyword">this</span>.file)</div><div class="line">    &#125;,</div><div class="line">    <span class="keyword">async</span> resChange (file) &#123;</div><div class="line">      <span class="comment">// 1：按照 修改时间+文件名称+最后修改时间计算MD5</span></div><div class="line">      <span class="keyword">let</span> fileMd5Value = <span class="keyword">await</span> <span class="keyword">this</span>.md5File(file)</div><div class="line">      <span class="comment">// 2：校验文件的MD5</span></div><div class="line">      <span class="keyword">let</span> result = <span class="keyword">await</span> <span class="keyword">this</span>.checkFileMD5(file.name, fileMd5Value)</div><div class="line">      <span class="comment">// 如果文件已存在, 就秒传</span></div><div class="line">      <span class="keyword">if</span> (result.file) &#123;</div><div class="line">        <span class="built_in">console</span>.log(<span class="string">'文件已存在，秒传'</span>)</div><div class="line">        <span class="keyword">return</span> <span class="literal">false</span></div><div class="line">      &#125;</div><div class="line">      <span class="comment">// 显示上传进度</span></div><div class="line">      <span class="keyword">this</span>.uploadProcessStyle = <span class="string">'100%'</span></div><div class="line">      <span class="comment">// 3：检查并上传MD5</span></div><div class="line">      <span class="keyword">await</span> <span class="keyword">this</span>.checkAndUploadChunk(fileMd5Value, result.chunkList)</div><div class="line">      <span class="comment">// 4: 通知服务器所有分片已上传完成</span></div><div class="line">      <span class="keyword">this</span>.notifyServer(fileMd5Value)</div><div class="line">    &#125;,</div><div class="line">    <span class="comment">/*  1、修改时间 + 文件名称 + 最后修改时间 =&gt; MD5 */</span></div><div class="line">    md5File (file) &#123;</div><div class="line">      <span class="keyword">let</span> _this = <span class="keyword">this</span></div><div class="line">      <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> &#123;</div><div class="line">        <span class="keyword">let</span> blobSlice =</div><div class="line">          File.prototype.slice ||</div><div class="line">          File.prototype.mozSlice ||</div><div class="line">          File.prototype.webkitSlice</div><div class="line">        <span class="keyword">let</span> currentChunk = <span class="number">0</span></div><div class="line">        <span class="keyword">let</span> _spark = <span class="keyword">new</span> SparkMD5.ArrayBuffer()</div><div class="line">        <span class="keyword">let</span> _fileReader = <span class="keyword">new</span> FileReader() <span class="comment">// H5强大的File Api</span></div><div class="line">        <span class="keyword">let</span> _chunks = <span class="number">100</span></div><div class="line">        <span class="keyword">let</span> _chunkSize = file.size / <span class="number">100</span></div><div class="line">        _this.chunks = _chunks</div><div class="line">        _this.chunkSize = _chunkSize</div><div class="line"></div><div class="line">        <span class="comment">/* 读文件 */</span></div><div class="line">        _fileReader.onload = <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</div><div class="line">          <span class="built_in">console</span>.log(<span class="string">'read chunk nr'</span>, currentChunk + <span class="number">1</span>, <span class="string">'of'</span>, _chunks)</div><div class="line">          _spark.append(e.target.result)</div><div class="line">          currentChunk++</div><div class="line">          <span class="keyword">if</span> (currentChunk &lt; _chunks) &#123;</div><div class="line">            loadNext()</div><div class="line">          &#125; <span class="keyword">else</span> &#123;</div><div class="line">            <span class="keyword">let</span> curr = +<span class="keyword">new</span> <span class="built_in">Date</span>()</div><div class="line">            <span class="built_in">console</span>.log(<span class="string">'上传完成'</span>)</div><div class="line">            <span class="keyword">let</span> result = _spark.end()</div><div class="line">            resolve(result)</div><div class="line">          &#125;</div><div class="line">        &#125;</div><div class="line">        <span class="comment">/* 出错 */</span></div><div class="line">        _fileReader.onerror = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</div><div class="line">          <span class="built_in">console</span>.warn(<span class="string">'something wrong!!!!'</span>)</div><div class="line">        &#125;</div><div class="line"></div><div class="line">        <span class="function"><span class="keyword">function</span> <span class="title">loadNext</span> (<span class="params"></span>) </span>&#123;</div><div class="line">          <span class="keyword">let</span> start = currentChunk * _chunkSize</div><div class="line">          <span class="keyword">let</span> end =</div><div class="line">            start + _chunkSize &gt;= file.size ? file.size : start + _chunkSize</div><div class="line">          _fileReader.readAsArrayBuffer(blobSlice.call(file, start, end))</div><div class="line">          _this.checkProcessStyle = currentChunk + <span class="number">1</span> + <span class="string">'%'</span></div><div class="line">        &#125;</div><div class="line">        loadNext()</div><div class="line">      &#125;)</div><div class="line">    &#125;,</div><div class="line">    <span class="comment">/*  2、校验文件的MD5 */</span></div><div class="line">    checkFileMD5 (fileName, fileMd5Value) &#123;</div><div class="line">      <span class="keyword">let</span> _this = <span class="keyword">this</span></div><div class="line">      <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> &#123;</div><div class="line">        <span class="keyword">let</span> url = <span class="string">`<span class="subst">$&#123;_this.baseUrl&#125;</span>/check/file?fileName=<span class="subst">$&#123;fileName&#125;</span>&amp;fileMd5Value=<span class="subst">$&#123;fileMd5Value&#125;</span>`</span></div><div class="line">        _this._$.getJSON(url, <span class="function"><span class="keyword">function</span> (<span class="params">data</span>) </span>&#123;</div><div class="line">          resolve(data)</div><div class="line">        &#125;)</div><div class="line">      &#125;)</div><div class="line">    &#125;,</div><div class="line">    <span class="comment">/* 3.1、上传chunk */</span></div><div class="line">    <span class="keyword">async</span> checkAndUploadChunk (fileMd5Value, chunkList) &#123;</div><div class="line">      <span class="keyword">this</span>.chunks = <span class="built_in">Math</span>.ceil(<span class="keyword">this</span>.fileSize / <span class="keyword">this</span>.chunkSize)</div><div class="line">      <span class="keyword">this</span>.hasUploaded = chunkList.length</div><div class="line"></div><div class="line">      <span class="keyword">for</span> (<span class="keyword">let</span> i = <span class="number">0</span>; i &lt; <span class="keyword">this</span>.chunks; i++) &#123;</div><div class="line">        <span class="keyword">let</span> exit = chunkList.indexOf(i + <span class="string">''</span>) &gt; <span class="number">-1</span></div><div class="line">        <span class="comment">// 如果已经存在, 则不用再上传当前块</span></div><div class="line">        <span class="keyword">if</span> (!exit) &#123;</div><div class="line">          <span class="keyword">let</span> index = <span class="keyword">await</span> <span class="keyword">this</span>.upload(i, fileMd5Value, <span class="keyword">this</span>.chunks)</div><div class="line">          <span class="keyword">this</span>.hasUploaded = <span class="keyword">this</span>.hasUploaded + <span class="number">1</span></div><div class="line">          <span class="keyword">let</span> radio = <span class="built_in">Math</span>.floor((<span class="keyword">this</span>.hasUploaded / <span class="keyword">this</span>.chunks) * <span class="number">100</span>)</div><div class="line">          <span class="built_in">console</span>.log(radio, <span class="string">':radio'</span>)</div><div class="line">          <span class="keyword">this</span>.uploadProcessStyle = radio + <span class="string">'%'</span></div><div class="line">        &#125;</div><div class="line">      &#125;</div><div class="line">    &#125;,</div><div class="line">    <span class="comment">/* 3.2上传chunk2 */</span></div><div class="line">    upload (i, fileMd5Value, chunks) &#123;</div><div class="line">      <span class="keyword">let</span> _this = <span class="keyword">this</span></div><div class="line">      <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> &#123;</div><div class="line">        <span class="keyword">let</span> end =</div><div class="line">          (i + <span class="number">1</span>) * _this.chunkSize &gt;= _this.file.size</div><div class="line">            ? _this.file.size</div><div class="line">            : (i + <span class="number">1</span>) * _this.chunkSize</div><div class="line">        <span class="keyword">let</span> _formData = <span class="keyword">new</span> FormData() <span class="comment">// 构造表单</span></div><div class="line">        _formData.append(<span class="string">'data'</span>, _this.file.slice(i * _this.chunkSize, end)) <span class="comment">// 切出文件的一部分</span></div><div class="line">        _formData.append(<span class="string">'total'</span>, _this.chunks) <span class="comment">// 总片数</span></div><div class="line">        _formData.append(<span class="string">'index'</span>, i) <span class="comment">// 当前是第几片</span></div><div class="line">        _formData.append(<span class="string">'fileMd5Value'</span>, fileMd5Value)</div><div class="line">        _this._$.ajax(&#123;</div><div class="line">          url: <span class="string">`<span class="subst">$&#123;_this.baseUrl&#125;</span>/upload`</span>,</div><div class="line">          type: <span class="string">'POST'</span>,</div><div class="line">          data: _formData,</div><div class="line">          <span class="keyword">async</span>: <span class="literal">true</span>,</div><div class="line">          processData: <span class="literal">false</span>,</div><div class="line">          contentType: <span class="literal">false</span>,</div><div class="line">          success: <span class="function"><span class="keyword">function</span> (<span class="params">data</span>) </span>&#123;</div><div class="line">            resolve(data.desc)</div><div class="line">          &#125;</div><div class="line">        &#125;)</div><div class="line">      &#125;)</div><div class="line">    &#125;,</div><div class="line">    <span class="comment">/* 4、通知服务器所有分片上传完成 */</span></div><div class="line">    notifyServer (fileMd5Value) &#123;</div><div class="line">      <span class="keyword">let</span> url = <span class="string">`<span class="subst">$&#123;<span class="keyword">this</span>.baseUrl&#125;</span>/merge?md5=<span class="subst">$&#123;fileMd5Value&#125;</span>&amp;fileName=<span class="subst">$&#123;<span class="keyword">this</span>.file.name&#125;</span>&amp;size=<span class="subst">$&#123;<span class="keyword">this</span>.file.size&#125;</span>`</span></div><div class="line">      <span class="keyword">this</span>._$.getJSON(url, <span class="function"><span class="keyword">function</span> (<span class="params">data</span>) </span>&#123;</div><div class="line">        alert(<span class="string">'上传成功'</span>)</div><div class="line">      &#125;)</div><div class="line">    &#125;</div><div class="line">  &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>style lang=”stylus”<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line">* &#123;</div><div class="line">  margin: 0;</div><div class="line">  padding: 0;</div><div class="line">  box-sizing: border-box;</div><div class="line">&#125;</div><div class="line">.process-wrap &#123;</div><div class="line">  width: 300px;</div><div class="line">  p &#123;</div><div class="line">    width: 100%;</div><div class="line">  &#125;</div><div class="line">  .progress &#123;</div><div class="line">    background: #c5c8ce;</div><div class="line">    height: 20px;</div><div class="line">    position: relative;</div><div class="line">    span &#123;</div><div class="line">      display: block;</div><div class="line">      background: #19be6b;</div><div class="line">      height: 100%;</div><div class="line">      width: 0;</div><div class="line">    &#125;</div><div class="line">  &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p><a href="https://github.com/HHardyy/vue-upload" target="_blank" rel="external">github上的源码地址：https://github.com/HHardyy/vue-upload</a></p>

        </div>

        <blockquote class="post-copyright">
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2020-02-04T10:16:16.839Z" itemprop="dateUpdated">2020-02-04 18:16:16</time>
</span><br>


        
        谢谢浏览，我会继续努力的，示例：<a href="/2020/02/04/前端大文件分片/" target="_blank" rel="external">http://yoursite.com/2020/02/04/前端大文件分片/</a>
        
    </div>
    <footer>
        <a href="http://yoursite.com">
            <img src="/img/avatar.jpg" alt="BingZhenhuang">
            BingZhenhuang
        </a>
    </footer>
</blockquote>

        
<div class="page-reward">
    <a id="rewardBtn" href="javascript:;" class="page-reward-btn waves-effect waves-circle waves-light">赏</a>
</div>



        <div class="post-footer">
            
	<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/HDFS/">HDFS</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/upload/">upload</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/分片/">分片</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/文件服务/">文件服务</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/静态资源/">静态资源</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://yoursite.com/2020/02/04/前端大文件分片/&title=《简单了解前端大文件分片》 — 小方块 - hhardyy.com&pic=http://yoursite.com/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://yoursite.com/2020/02/04/前端大文件分片/&title=《简单了解前端大文件分片》 — 小方块 - hhardyy.com&source=假设要把项目做成微服务架构，然后单独做个静态资源服务器。
" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://yoursite.com/2020/02/04/前端大文件分片/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《简单了解前端大文件分片》 — 小方块 - hhardyy.com&url=http://yoursite.com/2020/02/04/前端大文件分片/&via=http://yoursite.com" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://yoursite.com/2020/02/04/前端大文件分片/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/2020/03/14/React-hooks/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">React hooks</h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/2020/01/30/实时更新：新型肺炎疫情最新动态/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">新型肺炎疫情最新动态和患者同行查询工具</h4>
      </a>
    </div>
  
</nav>



    














</article>

<div id="reward" class="page-modal reward-lay">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <h3 class="reward-title">
        <i class="icon icon-quote-left"></i>
        🤠 请我喝可乐！
        <i class="icon icon-quote-right"></i>
    </h3>
    <div class="reward-content" style="width:50%">
        
        <div class="reward-code" style="text-align:center">
            <div style="width:300px;margin:0px auto;">
               <img id="rewardCode" style="width:50%;height:60%;display:block; margin:0px auto;" src="/img/alipay.jpg" alt="支付宝打赏二维码">
               <span style="display:inline-block; margin-bottom:20px;">0.88(支付宝 aliPay)</span>
               <img id="rewardCode" style="width:50%;height:60%;display:block; margin:0px auto;" src="/img/wechat.jpg" alt="微信打赏二维码">
               <span style="display:inline-block;">0.88(微信 weChat)</span>
            </div>
        </div>
    </div>
</div>



</div>

        <script>
!function(e,t,a){function n(){c(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"),o(),r()}function r(){for(var e=0;e<d.length;e++)d[e].alpha<=0?(t.body.removeChild(d[e].el),d.splice(e,1)):(d[e].y--,d[e].scale+=.004,d[e].alpha-=.013,d[e].el.style.cssText="left:"+d[e].x+"px;top:"+d[e].y+"px;opacity:"+d[e].alpha+";transform:scale("+d[e].scale+","+d[e].scale+") rotate(45deg);background:"+d[e].color+";z-index:99999");requestAnimationFrame(r)}function o(){var t="function"==typeof e.onclick&&e.onclick;e.onclick=function(e){t&&t(),i(e)}}function i(e){var a=t.createElement("div");a.className="heart",d.push({el:a,x:e.clientX-5,y:e.clientY-5,scale:1,alpha:1,color:s()}),t.body.appendChild(a)}function c(e){var a=t.createElement("style");a.type="text/css";try{a.appendChild(t.createTextNode(e))}catch(t){a.styleSheet.cssText=e}t.getElementsByTagName("head")[0].appendChild(a)}function s(){return"rgb("+~~(255*Math.random())+","+~~(255*Math.random())+","+~~(255*Math.random())+")"}var d=[];e.requestAnimationFrame=function(){return e.requestAnimationFrame||e.webkitRequestAnimationFrame||e.mozRequestAnimationFrame||e.oRequestAnimationFrame||e.msRequestAnimationFrame||function(e){setTimeout(e,1e3/60)}}(),n()}(window,document);
</script>
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<script>
    function secondToDate(second) {
        if (!second) {
            return 0;
        }
        var time = new Array(0, 0, 0, 0, 0);
        if (second >= 365 * 24 * 3600) {
            time[0] = parseInt(second / (365 * 24 * 3600));
            second %= 365 * 24 * 3600;
        }
        if (second >= 24 * 3600) {
            time[1] = parseInt(second / (24 * 3600));
            second %= 24 * 3600;
        }
        if (second >= 3600) {
            time[2] = parseInt(second / 3600);
            second %= 3600;
        }
        if (second >= 60) {
            time[3] = parseInt(second / 60);
            second %= 60;
        }
        if (second > 0) {
            time[4] = second;
        }
        return time;
    }</script>
<script type="text/javascript" language="javascript">
    function setTime() {
        var create_time = Math.round(new Date(Date.UTC(2017, 08, 18, 11, 42, 23)).getTime() / 1000);
        var timestamp = Math.round((new Date().getTime() + 8 * 60 * 60 * 1000) / 1000);
        currentTime = secondToDate((timestamp - create_time));
        currentTimeHtml = 'Running：' + currentTime[0] + '年 ' + currentTime[1] + '天 '
                + currentTime[2] + '时 ' + currentTime[3] + '分 ' + currentTime[4]
                + '秒';
        document.getElementById("htmer_time").innerHTML = currentTimeHtml;
    }    setInterval(setTime, 1000);
</script>
<footer class="footer">
    <div class="top">
        

        <p>
          <span id="busuanzi_container_page_pv">
             [&nbsp;浏览量：&nbsp;<span id="busuanzi_value_page_pv"></span>&nbsp;]
          </span>
        </p>
    </div>
    <div class="bottom">
        <p>
        <span>BingZhenhuang &copy; 2017 - 2020</span>
            <span>
                
                Power by <a href="https://hhardyy.github.io/" target="_blank">zhen On August 8</a> 
            </span>
            <span id="htmer_time" "></span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://yoursite.com/2020/02/04/前端大文件分片/&title=《简单了解前端大文件分片》 — 小方块 - hhardyy.com&pic=http://yoursite.com/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://yoursite.com/2020/02/04/前端大文件分片/&title=《简单了解前端大文件分片》 — 小方块 - hhardyy.com&source=假设要把项目做成微服务架构，然后单独做个静态资源服务器。
" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://yoursite.com/2020/02/04/前端大文件分片/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《简单了解前端大文件分片》 — 小方块 - hhardyy.com&url=http://yoursite.com/2020/02/04/前端大文件分片/&via=http://yoursite.com" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://yoursite.com/2020/02/04/前端大文件分片/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: true };


</script>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/main.min.js"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/search.min.js" async></script>








<script>
(function() {
    var OriginTitile = document.title, titleTime;
    document.addEventListener('visibilitychange', function() {
        if (document.hidden) {
            document.title = '(•‾̑⌣‾̑•)✧˖°回来看我';
            clearTimeout(titleTime);
        } else {
            document.title = '(゜-゜)つロ欢迎回来';
            titleTime = setTimeout(function() {
                document.title = OriginTitile;
            },2000);
        }
    });
})();
</script>



</body>
</html>
